﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8" />
    <link href="../lib/layui/css/layui.min.css" rel="stylesheet" />
    <style>
        .layui-form-select dl {
            max-height: 200px;
        }
    </style>
    <script type="text/javascript" src="../lib/Base64/base64.min.js"></script>
    <script type="text/javascript" src="../linq.js/linq.js"></script>
    <script src="../lib/layui/layui.js"></script>
    <script src="../lib/cookie/cookie.js"></script>
</head>
<body>
    <div class="layui-fluid">
        <form class="layui-form" lay-filter="sourceEditForm">
            <input type="hidden" id="id" name="id" />
            <input type="hidden" id="caseTypeName" name="caseTypeName" style="margin-top:10px;" />
            <div class="layui-form-item">
                <label class="layui-form-label">案件类型</label>
                <div class="layui-input-block">
                    <select name="caseTypeCode" id="caseTypeCode" lay-filter="caseTypeCode" lay-verify="required"></select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数据源编号</label>
                <div class="layui-input-block">
                    <input type="text" name="code" id="code" readonly class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item" style="margin-top:10px;">
                <label class="layui-form-label">数据源名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" required class="layui-input" />
                </div>
            </div>

            <div class="layui-form-item" style="text-align:center;">
                <a class="layui-btn" href="javascript:;" lay-submit lay-filter="savesource">保存</a>
            </div>
        </form>

    </div>
    <script type="text/javascript">
        function getrequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        };
        layui.use(['form'], function () {
            var form = layui.form;
            var $ = layui.$;
            //加载部门下拉框数据
            $.ajax({
                type: 'get',
                url: localStorage.getItem('hosttingaddr') + '/api/DataSource/getcasetypes',
                async: false,
                success: function (re) {
                    if (re.code == 1) {
                        $("#caseTypeCode").append("<option value=''>请选择</option>");
                        for (var i = 0; i < re.data.length; i++) {
                            $("#caseTypeCode").append("<option value='" + re.data[i].caseTypeCode + "'>" + re.data[i].caseTypeName + "</option>");
                        }
                        form.render();
                    }
                }
            });
            //form表单赋值
            $.ajax({
                type: 'get',
                url: localStorage.getItem('hosttingaddr') + '/api/DataSource/getdatasourcebyid?id=' + getrequest().id,
                async: false,
                success: function (re) {
                    if (re.code == 1) {
                        var source = re.data;
                        form.val("sourceEditForm", {
                            "id": source.id,
                            "caseTypeCode": source.caseTypeCode,
                            "caseTypeName": source.caseTypeName,
                            "code": source.code,
                            "name": source.name
                        });
                    }
                    layui.$("#caseTypeCode").attr("disabled", true);
                    form.render();

                }
            });

            //保存角色信息
            form.on('submit(savesource)', function (data) {
                var data = data;
                layui.$.ajax({
                    type: 'post',
                    url: localStorage.getItem('hosttingaddr') + '/api/DataSource/editdatasource',
                    headers: {
                        "user": getCookie("userinfo")
                    },
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    data: JSON.stringify(data.field),
                    success: function (re) {
                        if (re.code == 1) {
                            layer.msg('保存成功!', { icon: 1, time: 1000 });
                            parent.layui.table.reload('sourceTab');
                            var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                            parent.layer.close(index);
                        }
                    },
                    error: function (data) {
                        layer.msg('保存失败!', { icon: 1, time: 1000 });
                        parent.layui.table.reload('sourceTab');
                        var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.close(index);
                    }
                });
                return false;
            });
        })
    </script>
</body>
</html>